//
//  SearchGoodCollectionViewCell.m
//  Youhuiju
//
//  Created by 余尚飞 on 16/8/24.
//  Copyright © 2016年 yutenys. All rights reserved.
//

#import "SearchGoodCollectionViewCell.h"

@interface SearchGoodCollectionViewCell ()
@property (weak, nonatomic) IBOutlet UIImageView *goodImg;//商品图片
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;//商品标题
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;//商品价格


//适配
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *imgHig;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *titleLabelLeading;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *titleLabelTrailing;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *priceLabelTop;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *priceLabelHig;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *addCartHig;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *addCartWid;


@end


@implementation SearchGoodCollectionViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.imgHig.constant = 156 * FitH;
    
    self.titleLabelLeading.constant = 23 * FitW;
    self.titleLabelTrailing.constant = 23 * FitW;
    self.titleLabel.font = [UIFont systemFontOfSize:13 * FitH];
    
    self.priceLabelTop.constant = 10 * FitH;
    self.priceLabelHig.constant = 10 * FitH;
    self.priceLabel.font = [UIFont systemFontOfSize:13 * FitH];
    
    self.addCartHig.constant = 20 * FitH;
    self.addCartWid.constant = 35 * FitW;
    
    self.layer.cornerRadius = 6 * FitH;
    
    
    // 设置字体间每行的间距
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineHeightMultiple = 15.0f * FitH;
    paragraphStyle.maximumLineHeight = 15.0f * FitH;
    paragraphStyle.minimumLineHeight = 15.0f * FitH;
    paragraphStyle.lineSpacing = 4.0f * FitH;// 行间距
    NSString *string = @"Leaders丽得姿氨基酸面膜贴10片";
    NSDictionary *ats = @{
                          NSParagraphStyleAttributeName : paragraphStyle,
                          };
    self.titleLabel.attributedText = [[NSAttributedString alloc] initWithString:string attributes:ats];
    
    
    //关键字高亮
    NSString *result = @"¥ 100";
    NSString *keyWords = @"¥";
    //关键字标红效果
    NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc]initWithString:result];
    //获取关键字属性
    NSRange rang = [result rangeOfString:keyWords];
    //设置关键字属性
    [attributeString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithHexString:@"ff5f7b"],NSForegroundColorAttributeName,[UIFont systemFontOfSize:13 * FitH],NSFontAttributeName, nil] range:rang];
    //添加到label
    self.priceLabel.attributedText = attributeString;
    
    
    // Initialization code
}

- (IBAction)addCartAction:(UIButton *)sender {
    if (self.addCartButtonHandler)
    {
        self.addCartButtonHandler();
    }
}




@end
